package com.jolinlink.omiis.commons.redis.impl.singleton;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;

public class AbstractRedisProcessor {
	private static final Logger logger = LoggerFactory.getLogger(AbstractRedisProcessor.class);

	protected Jedis getJedisResources() {
		Jedis jedis = RedisPoolFactory.getInstance().createJedisClient();
		if (jedis == null || !jedis.isConnected()) {
			throw new RuntimeException("获取Redis-Client异常！");
		}
		return jedis;
	}

	/**
	 * 获取JedisCluster实例
	 * 
	 * @return
	 */
	protected JedisCluster getJedisCluster() {
		return RedisPoolFactory.getInstance().createJedisCluster();

	}

	protected void close(Jedis jedis) {
		try {
			RedisPoolFactory.getInstance().close(jedis);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}
}
